package com.mzj.saas.mservice.lockManager.controller;

import com.mzj.saas.commons.ResultBean;
import com.mzj.saas.mservice.lockManager.service.LockManagerPersonService;
import com.mzj.saas.mservice.lockManager.vo.LockUserVO;
import com.mzj.saas.mservice.lockManager.vo.UnbindPersonLockVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 智能锁管理个人接口
 */
@Controller
@RequestMapping("/lockManagerPerson")
public class LockManagerPersonController {
    @Autowired
    private LockManagerPersonService lockManagerPersonService;

    /**
     * 用户信息列表
     *
     * @param accessToken
     * @param lockId
     * @return
     */
    @GetMapping("/findLockUsers")
    @ResponseBody
    public ResultBean<List<LockUserVO>> findLockUsers(@RequestHeader String accessToken,
                                                      @RequestParam(value = "lockId") Long lockId) {
        return lockManagerPersonService.findLockUsers(accessToken, lockId);
    }

    /**
     * 解绑
     *
     * @param accessToken
     * @param vo
     * @return
     */
    @PostMapping("/unbindPersonLock")
    @ResponseBody
    public ResultBean<Object> unbindPersonLock(@RequestHeader String accessToken,
                                               @RequestBody UnbindPersonLockVO vo) {
        return lockManagerPersonService.unbindPersonLock(accessToken, vo);
    }

    /**
     * 启用或禁用
     *
     * @param accessToken
     * @param lockAuthId
     * @param status      操作类型：0禁用 1启用
     * @return
     */
    @GetMapping("/updateUserStatus")
    @ResponseBody
    public ResultBean<Object> updateUserStatus(@RequestHeader String accessToken,
                                               @RequestParam(value = "lockAuthId") Long lockAuthId,
                                               @RequestParam(value = "status") Integer status) {
        return lockManagerPersonService.updateUserStatus(accessToken, lockAuthId, status);
    }

    /**
     * 删除
     *
     * @param accessToken
     * @param lockAuthId
     * @return
     */
    @GetMapping("/deleteUser")
    @ResponseBody
    public ResultBean<Object> deleteUser(@RequestHeader String accessToken,
                                         @RequestParam(value = "lockAuthId") Long lockAuthId) {
        return lockManagerPersonService.deleteUser(accessToken, lockAuthId);
    }

    /**
     * 添加用户
     *
     * @param accessToken
     * @param lockId
     * @param userName
     * @return
     */
    @GetMapping("/addUser")
    @ResponseBody
    public ResultBean<Object> addUser(@RequestHeader String accessToken,
                                      @RequestParam(value = "lockId") Long lockId,
                                      @RequestParam(value = "userName") String userName,
                                      @RequestParam(value = "phone") String phone) {
        return lockManagerPersonService.addUser(accessToken, lockId, userName, phone);
    }


}
